//
//  UIViewControllerExtension.swift
//  XiaoweHealthy
//
//  Created by Riven on 2022/3/25.
//

import Foundation
import UIKit


//public extension UIViewController {
//    
//    static var isSetNavShadowColorWhenSetNavColor: Bool = false
//
//    func setNavTransparent() {
//        navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
//        navigationController?.navigationBar.shadowImage = UIImage()
//    }
//    
//    func resetNavFromTransparent() {
//        navigationController?.navigationBar.setBackgroundImage(nil, for: .default)
//        navigationController?.navigationBar.shadowImage = nil
//    }
//    
//    func setNav(color: UIColor) {
////        navigationController?.navigationBar.setBackgroundImage(UIImage(color: color, size: CGSize(width: 1, height: 1)), for: .default)
////        navigationController?.navigationBar.shadowImage = UIImage()
//        
//        var shadowColor: UIColor? = nil
//        if Self.isSetNavShadowColorWhenSetNavColor {
//            shadowColor = color
//        }
//        setNav(color: color, shadowColor: shadowColor)
//    }
//    
//    func setNav(color: UIColor, shadowColor: UIColor?, navTitleColor: UIColor? = nil, navTitleFont: UIFont? = nil) {
////        navigationController?.navigationBar.setBackgroundImage(UIImage(color: color, size: CGSize(width: 1, height: 1)), for: .default)
////        navigationController?.navigationBar.shadowImage = UIImage()
//        
//        let appearance = UINavigationBarAppearance()
//        appearance.configureWithOpaqueBackground()
//        appearance.backgroundColor = color
//        if let shadowColor = shadowColor {
//            appearance.shadowColor = shadowColor
//        }
//        
//        var ttAttributes: [NSAttributedString.Key : Any] = [:]
//        if let navTitleColor = navTitleColor {
//            ttAttributes[.foregroundColor] = navTitleColor
//        }
//        if let navTitleFont = navTitleFont {
//            ttAttributes[.font] = navTitleFont
//        }
//        if !ttAttributes.isEmpty {
//            appearance.titleTextAttributes = ttAttributes
//        }
//        navigationController?.navigationBar.standardAppearance = appearance
//        navigationController?.navigationBar.scrollEdgeAppearance = appearance
//        navigationController?.navigationBar.compactAppearance = appearance
//    }
//    
//    func setNavHidden(_ isHidden: Bool, animated: Bool = true, async: Bool = false) {
//        guard let nav = navigationController else {
//            return
//        }
//        
//        if async {
//            DispatchQueue.main.async {
//                nav.setNavigationBarHidden(isHidden, animated: animated)
//            }
//        } else {
//            nav.setNavigationBarHidden(isHidden, animated: animated)
//        }
//    }
//    
////    public func addNavInteractivePopGestureRecognizerDelegate() {
////        navigationController?.addInteractivePopGestureRecognizerDelegate()
////    }
////
////    public func removeNavInteractivePopGestureRecognizerDelegate() {
////        navigationController?.removeInteractivePopGestureRecognizerDelegate()
////    }
//    
//    /// navigationController 倒数第二个 VC
//    func navTopPreviousVC() -> UIViewController? {
//        var vcArray = navigationController?.viewControllers
//        vcArray?.removeLast()
//        
//        return vcArray?.last
//    }
//
//}

//extension UIViewController: UIGestureRecognizerDelegate {
//    
//    public func addNavInteractivePopGestureRecognizerDelegate() {
//        navigationController?.interactivePopGestureRecognizer?.delegate = self
//    }
//    
//    public func removeNavInteractivePopGestureRecognizerDelegate() {
//        navigationController?.interactivePopGestureRecognizer?.delegate = nil
//    }
//    
//    public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
//        if children.count == 1 {
//            return false
//        }
//        
//        return true
//    }
//    
//}
